{extend name="admin@index_layout"/}
{block name="main"}

<div class="layui-card">
    <div class="layui-card-header">语言库列表 | {:onSiteName()}</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <blockquote class="alert alert-success-light">语言包添加或编辑完成后，请点击【生成语言包】前台才会更新相应数据！</blockquote>
        </div>
        <div class="layui-tab">
            <ul class="layui-tab-title">
                {volist name="langGroups" id="vo"}
                <li class="{if $vo['id']==$group}layui-this{/if}"><a href="{:url('cms/lang/index',['group'=>$vo['id']])}">{$vo.name}</a></li>
                {/volist}
            </ul>
            <div class="layui-tab-content">
                <table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
            </div>
        </div>
    </div>

</div>
<script type="text/html" id="barTool">
    {{# if({$push}){ }}
    <a data-open='{:url("push/lang")}?id={{ d.id }}' data-width="900" data-height="600" class="layui-btn layui-btn-xs layui-btn-warm" title="推送并翻译">推送</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-btn-disabled" title="推送并翻译">推送</a>
    {{# } }}
    {{# if(d.group==1){ }}
    <a href='javascript:;' class="layui-btn layui-btn-normal layui-btn-xs copy" data-clipboard-text="{literal}{:lang('{{d.name}}')}{/literal}">调用</a>
    {{# } }}
    {{# if(d.group==2){ }}
    <a href='javascript:;' class="layui-btn layui-btn-xs layui-btn-normal copy" data-clipboard-text="{literal}{:lang('{{d.name}}')}{/literal}">调用</a>
    {{# } }}
    {{# if(d.group==3){ }}
    <a href='javascript:;' class="layui-btn layui-btn-xs layui-btn-normal copy" data-clipboard-text="{literal}patch('{{d.name}}'){/literal}">调用</a>
    {{# } }}
    <a data-open='{:url("edit")}?id={{ d.id }}' data-width="900" data-height="600" data-title="编辑" class="layui-btn layui-btn-xs">编辑</a>
    <a href='{:url("del")}?ids={{ d.id }}' class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
</script>

<script type="text/html" id="groupTpl">
    {{# if(d.group == 1){ }}
    内容
    {{# } else if(d.group == 2) { }}
    会员
    {{# } else { }}
    系统
    {{# } }}
</script>
{/block}

{block name="script"}
<script>
layui.use(['yznTable','clipboard'], function() {
    var table = layui.yznTable,
        $ = layui.$,
        form = layui.form,
        clipboard =  layui.clipboard;

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTable',
        add_url: "{:url('add',['group'=>$group])}",
        modify_url:'{:url("multi")}',
        delete_url: "{:url('del')}",
    };

    table.render({
        init: init,
        toolbar: ['refresh',[{
            text: '添加',
            title: '添加',
            url: init.add_url,
            method: 'open',
            class: 'layui-btn layui-btn-normal layui-btn-sm',
            icon: 'iconfont icon-add',
            extend: 'data-width="900" data-height="600"',
        }], [{
            text: "生成语言包",
            url: "{:url('cache')}",
            method: 'request',
            icon: 'iconfont icon-right',
            class: 'layui-btn layui-btn-sm layui-btn-danger',
            extend: 'data-table="currentTable"',
        }]
        ],
        url: '{:url("index")}',
        url: '{:url("index",["group"=>$group])}',
        cols: [
            [
                { field: 'id', title: 'ID', width: 70, align:'center',search:false },
			    { field: 'listorder', width: 70, title: '排序', edit: 'text',search:false },
                { field: 'name', title: '名称', width: 200, searchOp: 'like'},
                { field: 'title', title: '标题', width: 200, searchOp: 'like' },
                { field: 'site', width: 150, title: '已发站点', align: "center"},
                { field: 'group', width: 100, title: '分类', templet: '#groupTpl', align: "center", selectList: { 1: '内容', 2: '会员', 3: '系统'  } },
                { field: 'remark', title: '备注' },
				{ field: 'update_time', width: 200, title: '更新时间', search: 'range', align:'center',search:false },
                { field: 'status', width: 100, align: "center", title: '状态', unresize: true,templet: yznTable.formatter.switch },
                { fixed: 'right', width: 220, title: '操作', toolbar: '#barTool', align:'center' }
            ]
        ],
        page: {}
    });

    var clipboard = new clipboard('.copy');
    clipboard.on('success', function(e) {
        layer.msg("复制成功",{ icon: 1});
    });
    clipboard.on('error', function(e) {
        layer.msg("复制失败！请手动调用",{ icon: 2});
    });

	 //监听单元格编辑
	 table.on('edit(dataTable)', function(obj) {
        var value = obj.value,data = obj.data;
        $.post('{:url("cms/lang/listorder")}', {'id': data.id,'value':value }, function(data) {
            if (data.code == 1) {
                layer.msg(data.msg);
            }else{
                layer.msg(data.msg);
            }

        })
    });
});
</script>
{/block}


